home *** CD-ROM | disk | FTP | other *** search
- Path: li.net!usenet
- From: bsilvern@li.net (Bob Silvern)
- Newsgroups: comp.lang.c++
- Subject: Re: BORLAND C++ 4.5 wont add .1 and .9
- Date: Thu, 25 Jan 1996 17:15:06 GMT
- Organization: Harmony Graphics
- Message-ID: <4e8dqv$ins@linet02.li.net>
- References: <1996Jan18.044900.10609@oasis.enmu.edu> <96019.113901CWF102@psuvm.psu.edu>
- NNTP-Posting-Host: lisuser44.li.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- The Mighty Stymie <CWF102@psuvm.psu.edu> wrote:
-
- >I believe your problem has something to do with the way Borland stroes floating
- >point numbers. I had a similar problem recently:
-
- >if(x>0.1)
- > do this
- >else
- > do that
-
- >If x=0.1 it would still do "this" and it wouldn't do "that" until x<0.1
- >I was only concerned with increments or decrements of 0.1, so I did this
-
- >if(x>0.11)
- > do this
- >else
- > do that
-
- >If you tack on a digit beyond the on your concerned with, things may work. As
- >I finish this note, I forget what your problem was specifically, but I know it
- >was similar to this. :)
- >-christopher w. felter
-
- >*******************************************************************************
- >* ____ __ __ ____ Christopher W. Felter (alias: The Mighty Stymie) *
- >* ---\ / / /--- cwf102@psuvm.psu.edu cwf102@email.psu.edu *
- >* ---\ / /___/-- felt43@eetsg00.bd.psu.edu stymie@psu.edu *
- >* \/ / / http://metro.turnpike.net/S/stymie *
- >* / / "If I get home and there's sour cream on them, those *
- >* / food, my husband's gonna be pissed. I said pissed!" *
- >* / - Overweight, midwestern woman at Taco Bell, Oxford, *
- >* Ohio (September 11, 1995) *
- >*******************************************************************************
-
- How are you assigning the value 0.1 to x? If you are directly assinging the
- value (i.e. x=0.1), then I'm surprised this doesn't work. However, if you are
- getting there by floating point calculations, (i.e. x=0.05; x+=x) then you must
- consider that floating point numbers are internally stored as binary
- approximations. Even though the debugger may display the value as 0.1 rounding
- the display off to 8 significant digits, the presise value which is limited to
- the precision of your machine, in this case 4 bytes for a float, may be closer
- to 0.100000000000000000000000001. Thus x > 0.1. This is a problem you will
- find when doing floating point comparisons on any platform with any compiler,
- not just Borland's.
-
-
-